﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Collections.Specialized;

using Layers;

namespace HoldemGame
{
    public struct XY
    {
        public double X;
        public double Y;

        public XY(double x, double y)
        {
            X=x;
            Y=y;
        }

        public override string  ToString()
        {
            return string.Format("({0},{1})",X,Y);
        }

        public override bool  Equals(object obj)
        {
            if(obj is XY)
            {
                XY xy = (XY)obj;
                return xy.X == X && xy.Y == Y;
            }
            return false;
        }
    }

    public interface IChartData
    {
        int Count { get; }
        string ID { get; }

        object this[int i] {get;}

        event NotifyCollectionChangedEventHandler Changed;
    }

    public interface IChartData<T>:IChartData
    {
        T this[int index] { get; }
    }

    public interface IColorable
    {
        Color Color{get;}
    }

    public class ChartDataList<T> : IChartData<T>, IColorable
    {
        private IList<T> _impl;
        private string _id;
        private NotifyCollectionChangedEventHandler _changed;
        private Color _color = Color.Black;


        public ChartDataList(string id, IList<T> impl)
        {
            _id = id;
            _impl = impl;
        }

        public ChartDataList(string id)
        {
            _id = id;
            _impl = Factory.NewList<T>();
        }

        #region IXYChartData Members

        public int Count
        {
            get { return _impl.Count; }
        }

        public T this[int index]
        {
            get { return _impl[index]; }
            set { _impl[index] = value;}
        }

        object IChartData.this[int index]
        {
            get { return _impl[index]; }
        }

        public void Add(T xy)
        {
            _impl.Add(xy);
            if (null != _changed)
                _changed(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, xy, _impl.Count-1));
        }

        public Color Color { get { return _color; } set { _color=value;} }

        public void Clear()
        {
            _impl.Clear();
            if (null != _changed)
                _changed(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }

        public string ID
        {
            get { return _id; }
            set { _id=value;}
        }

        public event NotifyCollectionChangedEventHandler Changed
        {
            add { _changed+=value;}
            remove { _changed-=value;}
        }

        #endregion
    }

    public class XYChartDataList : ChartDataList<XY>
    {

        public XYChartDataList(string id) : base(id) { }
        public void Add(double x, double y)
        {
            Add(new XY(x, y));
        }
    }

    public class DoubleChartDataList : ChartDataList<double>
    {
        public DoubleChartDataList(string id) : base(id) { }

        public void Add(double[] values, int start, int count)
        {
            for (int i = start; i - start < count; i++)
                Add(values[i]);
        }

        public void Add(double[] values)
        {
            Add(values, 0, values.Length);
        }
    }
 }